package main

import (
	"minio-webhook/api" // 请替换为实际路径
	"net/http"
	"os"

	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

func main() {

	logrus.SetFormatter(&logrus.JSONFormatter{})

	if level, err := logrus.ParseLevel(os.Getenv("LOG_LEVEL")); err == nil {
		logrus.SetLevel(level)
	} else {
		logrus.SetLevel(logrus.InfoLevel)
	}

	r := gin.Default()

	r.POST("/minio/webhook", api.HandleWebhook)

	// minio定期检查webhook是否可用，这里接收检查HEAD请求
	r.HEAD("/minio/webhook", func(c *gin.Context) {
		c.Status(http.StatusOK)
	})

	r.Run(":8080")
}
